#include<iostream>
using namespace std;
class CVector
{
    private:
        int *data;
        int n;
        static int sum;
    public:
        CVector()
        {
            n=5;
            data=new int[n];
            for(int i=0;i<n;i++)
            {
                data[i]=i;
            }
        }
        CVector(int n1,int* a)
        {
            data=new int[n1];
            n=n1;
            for(int i=0;i<n1;i++)
            {
                data[i]=a[i];
                sum+=data[i];
            }
        }
        void Print()
        {
            for(int i=0;i<n;i++)
            {
                if(i!=0)
                    cout<<" ";
                cout<<data[i];
            }
            cout<<endl;
        }
        ~CVector()
        {
            for(int i=0;i<n;i++)
            {
                sum-=data[i];
            }
            if(data)
                delete[] data;
        }
        CVector(const CVector& tmp)
        {
            n = tmp.n;
            data = new int[n];
            for (int i = 0; i < n; i++)
            {
                data[i] = tmp.data[i];
            }
        }
        void GetPrisum()
        {
            cout<<sum<<endl;
        }
        CVector set(int n1,int* a)
        {
            delete[] data;
            data=new int[n1];
            n=n1;
            for(int i=0;i<n1;i++)
            {
                data[i]=a[i];
                sum+=data[i];
            }
        }

};
int CVector::sum=0;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int t2;
        cin>>t2;
        CVector array[t2]; 
        for(int i=0;i<t2;++i)
        {
            int m;
            cin>>m;
            int aa[m];
            for(int j=0;j<m;j++)
            {
                cin>>aa[j];
            }
            array[i].set(m,aa);
            array[i].Print();
        }
        array[0].GetPrisum();
    }
}